package com.heima.nativejdbc;

import java.sql.*;


public class JdbcDemo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接对象
        String url = "jdbc:mysql:///ssm";
        String userName = "root";
        String password = "1234";
        Connection conn = DriverManager.getConnection(url, userName, password);
        //3.获取预编译对象
        String sql = "select * from account where id=?";
        PreparedStatement pstm = conn.prepareStatement(sql);
        //4.设置参数
        pstm.setInt(1, 4);
        //5.查询
        ResultSet rs = pstm.executeQuery();
        //6.解析结果集，获取数据
        while (rs.next()) {
            int id = rs.getInt("id");
            String name = rs.getString("name");
            float money = rs.getFloat("money");
            System.out.println("name:" + name + ",id:" + id + ",money:" + money);
        }
        //7.释放资源，关闭连接
        rs.close();
        pstm.close();
        conn.close();
    }
}
